
import java.util.ArrayList;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

import il.ac.braude.sona.constants.TestingParamKit;
import il.ac.braude.sona.control.CloseRequestController;
import il.ac.braude.sona.control.ViewRequestController;
import il.ac.braude.sona.gui.SONAFrame;
import il.ac.braude.sona.ocsf.client.ConnectToClientForTesting;
import fit.ActionFixture;

public class ClosingRequestFitTest extends ActionFixture {
	private ViewRequestController viewController= new ViewRequestController();
	private CloseRequestController closeController = new CloseRequestController();
	private ConnectToClientForTesting connection= new ConnectToClientForTesting();
	private TestingParamKit TestKit=TestingParamKit.getTestingKit();
	
	private String currentRid;

	public void startClosingRequestFitTest() {

	}

	public void startProgramWithServer(String host) {
		showTestingMessage();
		TestKit.startTestMode();
		connection.setHost(host);
		ArrayList<Object> values=new ArrayList<Object>();
		values.add("avihay");
		values.add("1234");
		connection.connectToClient(values);
	}

	public void requestIdToClose(String Id) {
		currentRid = Id;
		viewController.viewReqFromMssg(currentRid);
		TestKit.waitForNotify();
	}

	public void closeRequest() {
		closeController.closeAndNotifyUser(
				viewController.getTestingChangeReq(),
				viewController.getTestReqFrame());
		
		TestKit.waitForNotify();
	}

	public boolean emailSent() {
		return TestKit.mailSent;
	}

	public String requestStatus() {
		viewController.viewReqFromMssg(currentRid);
		TestKit.waitForNotify();
		return viewController.getTestingChangeReq().getValue("Status");
	}

	public void userConfirmation() {
		closeController.execUserConfirmation(
				viewController.getTestingChangeReq(),
				viewController.getTestReqFrame());
		
		TestKit.waitForNotify();

	}
	
	private void showTestingMessage(){
		SONAFrame frame = null;
		JDialog dialog = new JDialog(frame, false); // Sets its owner but makes it non-modal 
		JOptionPane optionPane = new JOptionPane("Please dont press on poped windows, wait until test finish"); // Same arguments as in JOptionPane.showMessageDialog(...)
		dialog.getContentPane().add(optionPane); // Adds the JOptionPane to the dialog
		dialog.pack(); // Packs the dialog so that the JOptionPane can be seen
		dialog.setVisible(true); // Shows the dialog
	}
}
